package base.exa18;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class ScannerStudy {

    public static void main(String[] args) throws FileNotFoundException {
        //扫描读取控制台输入
        ScannerSysIn();

        //扫描读取指定文件中的数据
        Scanner sc1 = new Scanner(new File("README.md"));
        while (sc1.hasNextLong()) {
            long aLong = sc1.nextLong();
            System.out.println(aLong);
        }

        //Scanner也可以用作处理字符串，例如
        String input = "1 fish 2 fish red fish blue fish";
        Scanner s = new Scanner(input).useDelimiter("\\s*fish\\s*");
        System.out.println(s.nextInt());
        System.out.println(s.nextInt());
        System.out.println(s.next());
        System.out.println(s.next());
        s.close();
    }

    /**
     * Scanner作为数据扫描器，
     * 它可以让控制台输入的字符放到程序中来，
     * 这是的最简单用法
     */
    public static void ScannerSysIn(){
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        System.out.println(str);
    }

}
